<?php

namespace View;

class UserView 
{
	//Privata strängar
	private $getUserName = "UserName";
	private $getPassword = "Password";
	private $getRepeatedPassword = "RepeatedPassword";
	private $getSubmit = "Register";
	
	//Konstanter
	const REGISTER_CTRL_HEADER = 1;
	const ERROR_USER_EXISTS = 2;
	const USER_ADDED_SUCCESS = 3;
	
	//Retunerar rubriker via konstantanrop
	public function RenderHeader($header)
	{
		switch($header)
		{
			case self::REGISTER_CTRL_HEADER;
				return "<div class='contentHeader'><h2>Register new user</h2></div>";
				break;												
		}			
	}	

	//Retunerar meddelanden via konstantanrop	
	public function RenderMessage($message)
	{
		switch($message)
		{
			case self::ERROR_USER_EXISTS;
				return "<p class='errorMsg'> Username: " . $this->GetUserName() . " allready exists.</p>";
				break;
			case self::USER_ADDED_SUCCESS;
				return "<p class='msg'>User " . $this->GetUserName() . " have been registed</p>";
				break;	
		}
	}			

	//Retunerar felmeddelanden via array-anrop
	public function RenderErrorArray($errorArray)
	{
		$ret = "<div class='errorMsg'>";
		
		foreach($errorArray as $error)
		{
			$ret .= "<p>" .$error . "</p>";
		}
		
		$ret .= "</div>";					
		return $ret;		
	}
	
	//Retunerar ett registreringsformulär
	public function RenderRegForm() 
	{
	    return $RegisterForm = 

	    "<form name='frmRegUser' id='frmRegUser' method='post'>	    		
			<p class='regName'>Name:</p>			
			<input type='text' class='nameInput' name='$this->getUserName' id='RegName' />
			<p class='regPw'>Password:</p>							
			<input type='password' class='pwInput' name='$this->getPassword' id='RegPassword' />
			<p class='regRepeatedPw'>Repeat password:</p>							
			<input type='password' class='repPwInput' name='$this->getRepeatedPassword' id='RepPassword' />					
			
			<input type='submit' value='Register' name='$this->getSubmit' id='Register' class='button' />	
					  			
		</form>";
	}

	//Retunerar HTML för en användarpanel	
	public function RenderUserPanelContent()
	{
		$newTopicLink = NavigationView::getNewTopicLink();
		$myTopicsAndPostsLink = NavigationView::getMyTopicsAndPostsLink();		
		
		$ret =  "<div class='contentHeader'><h2>User panel</h2></div>"; 
		$ret .= "<div class='userPanel'><p><a href='$newTopicLink'>Create new topic</a></p>";	
		$ret .= "<p><a href='$myTopicsAndPostsLink'>My topics and posts</a></div></p>";	
		
		return $ret;
	}		
		
	//Retunerar användarnamnet, annars NULL
	public function GetUserName() 
	{	  	
		if (isset($_POST[$this->getUserName]) == TRUE)
		{				 		
			return $_POST[$this->getUserName];
		}
		
		return NULL;		
	}
	
	//Retunerar lösenordet, annars NULL
	public function GetPassword() 
	{	
		if (isset($_POST[$this->getPassword]) == TRUE)
		{
			return $_POST[$this->getPassword];
		}
				
		return NULL;			
	}

	//Retunerar det repeterade lösenordet, annars NULL	
	public function GetRepeatedPassword() 
	{	
		if (isset($_POST[$this->getRepeatedPassword]) == TRUE)
		{
			return $_POST[$this->getRepeatedPassword];
		}
				
		return NULL;			
	}	

	//Retunerar TRUE om man tryckt på Register knappen, annars FALSE	
	public function TriedToRegister() 
	{	
		if (isset($_POST[$this->getSubmit]))
		{   			
			return TRUE;  	
		}
				
		return FALSE;
	   		
	}		
				       	
} 
  

?>
  